package com.bjdd.jdy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bjdd.jdy.R;
import com.bjdd.jdy.entity.NewsBean;
import com.bjdd.jdy.util.DateUtils;
import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;
import com.zhy.autolayout.AutoLinearLayout;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/5/3.
 */

public class NewsAdapter extends SwipeMenuAdapter<NewsAdapter.MyViewHolder> {

    private Context mContext;
    private List<NewsBean> newsBeanList;

    public NewsAdapter(Context context, List<NewsBean> list) {
        this.mContext = context;
        this.newsBeanList = list;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tvNewsTitle.setText(newsBeanList.get(position).getContent());
        String title = "通知";
        switch (newsBeanList.get(position).getType()){
            case 0:
                title = "通知";
                break;
            case 1:
                title = "自由人通知";
                break;
            case 3:
                title = "个人通知";
                break;
        }
        holder.tvNewsType.setText(title);
        holder.tvNewsTime.setText(DateUtils.formatDateTime(newsBeanList.get(position).getCreateTime()));
        holder.all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                JumpUtil.toNewsDetail(mContext,newsBeanList.get(position).getType(),newsBeanList.get(position).getCreateTime(),newsBeanList.get(position).getContent());
            }
        });
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_news, parent, false);
        return view;
    }

    @Override
    public MyViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        MyViewHolder viewHolder;
        viewHolder = new MyViewHolder(realContentView);
        return viewHolder;
    }


    @Override
    public int getItemCount() {
        return newsBeanList.size();
    }


    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_news_type)
        TextView tvNewsType;
        @Bind(R.id.tv_news_time)
        TextView tvNewsTime;
        @Bind(R.id.tv_news_title)
        TextView tvNewsTitle;
        @Bind(R.id.new_item_view)
        AutoLinearLayout all;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
